package team.star.werespos.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import team.star.werespos.model.entity.OrderMaster;

import java.util.List;
import java.util.Map;

/**
 * OrderMasterMapper interface<br/>
 *
 * @author hdonghong
 * @since 2019/05/04
 */
public interface OrderMasterMapper extends BaseMapper<OrderMaster> {

    @Select("select SUM(order_amount) amount, DATE_FORMAT(create_time,'%Y-%m-%d') days from order_master GROUP BY days HAVING days LIKE CONCAT(#{year}, '%') order by days DESC LIMIT 10")
    List<Map> getTurnOverByDay(@Param("year") int year);

    @Select("select SUM(order_amount) amount, DATE_FORMAT(create_time,'%Y-%u') weeks from order_master GROUP BY weeks HAVING weeks LIKE CONCAT(#{year}, '%') order by weeks DESC LIMIT 10")
    List<Map> getTurnOverByWeek(@Param("year") int year);

    @Select("select SUM(order_amount) amount, DATE_FORMAT(create_time,'%Y-%m') months from order_master GROUP BY months HAVING months LIKE CONCAT(#{year}, '%') order by months DESC")
    List<Map> getTurnOverByMonth(@Param("year") int year);

    @Select("select SUM(order_amount) amount, CONCAT(YEAR(create_time), '-', QUARTER(create_time)) seasons from order_master GROUP BY seasons HAVING seasons LIKE CONCAT(#{year}, '%')  ORDER BY seasons DESC")
    List<Map> getTurnOverBySeason(@Param("year") int year);
}
